import numpy as np

data = [
    [1, 1, 1, 0],
    [0, 1, 2, 1]
]

data = np.asarray(data)

x = data[:, 0:3]
x = np.hstack([x, np.ones((len(x), 1))])
y = data[:, 3].T

theta = np.linalg.inv(x.T @ x) @ x.T @ y
# 求逆矩阵为不可逆矩阵，出现了异常，验证了解析解方法不总是可行的